package com.weed.table.rowhead;

import javax.swing.event.ChangeListener;
import javax.swing.event.ChangeEvent;
import java.awt.Point;
import javax.swing.JViewport;

/*** 函数说明：
 *     滚动条上下改变时，改变行头的大小。
 * 作者     日期     说明
 * 卓志成   20080119 整理。
 *
 */
public class RowHeadChangeHandler implements ChangeListener {
    JViewport centerHead = null;
    public RowHeadChangeHandler(JViewport centerHead){
        this.centerHead = centerHead;
    }

    public void stateChanged(ChangeEvent e) {
        syncScrollPaneWithViewport((JViewport)e.getSource());
    }

    /**处理行头的显示。*/
    protected void syncScrollPaneWithViewport(JViewport rowHead) {
        if (rowHead != null && centerHead != null) {
            Point p = centerHead.getViewPosition();
            p.y = rowHead.getViewPosition().y;
            centerHead.setViewPosition(p);
        }
    }

}
